package com.ostrich.cloud.ostrichUserService.infra.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ostrich.cloud.ostrichUserService.infra.model.Customer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ostrich.cloud.ostrichUserService.infra.model.UserParent;
import com.ostrich.ostrichUserService.dto.CustomerDto;
import com.ostrich.ostrichUserService.dto.UserParentDto;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author Lucas
 * @since 2022-10-26
 */
public interface CustomerMapper extends BaseMapper<Customer> {

    @Select("<script>"+
            "SELECT * " +
            "from customer" +
            "<where>" +
            "<if test='status != null and status.trim() != &quot;&quot;'>" +
            "and customer_status = #{status}" +
            "</if>" +
            "</where>" +
            "</script>")
    @Results(id="gets",value = {
            @Result(property = "customerId",column = "customer_id",id = true),
            @Result(property = "userParent",column = "parent_id",one = @One(
               select = "com.ostrich.cloud.ostrichUserService.infra.mapper.CustomerMapper.getUserParentById"
            ))
    })
    IPage<CustomerDto> getAllCusMessage(IPage<CustomerDto> page,@Param("status") String status);

    @Select("select  * from  user_parent where  parent_id=#{id}")
    UserParentDto getUserParentById(Integer id);
}
